package com.xuzz.study.aop.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author xuzz
 * @description
 * @date 2019-12-04 11:15
 */
public class MathJDKAOP implements InvocationHandler  {

    Object target;
    public MathJDKAOP(Object target)
    {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        System.out.println("before");
        Object result = method.invoke(target,args);
        System.out.println("after");
        return result;

    }

    public Object getInstance()
    {
        return Proxy.newProxyInstance(target.getClass().getClassLoader(),target.getClass().getInterfaces(),this);
    }
}
